<?php
$lang = Yii::app()->session['_lang'] ? : 'en';
$ii = 0;
if (isset($params) && count($params) > 0) {
    $hotel = Yii::app()->session['_hotel'];
    $cur = array();
    $selected = array();
    foreach ($listCurrency['rates'] as $key => $currency) {
        $cur[$key] = $currency['name'] . ' (' . $key . ')';
        if (Yii::app()->session['_change_currency'] == $key) {
            $selected[$key]['selected'] = true;
        } else {
            $selected[$key]['selected'] = false;
        }
    }
    ?>

    <section class="step_booking">
        <img src="<?= Yii::app()->theme->baseUrl ?>/images/step2_<?= $lang ?>.png">
        <article class="step2">
            <div class="nabar">
                <h2><?= $hotel_info->fullName; ?></h2>
            </div>
            <div class="modify-date">
                <div class="date"><strong><?= str_replace('-', '/', $fromDate) . ' - ' . str_replace('-', '/', $toDate) ?></strong> <span><?= $night ?> night(s)</span><br>
                    <?= $adult ?> adult(s), <?= $child ?> child(ren), <?= $extrabed ?> extrabed
                    <a href="javascript:void(0);" id="modify_date">Modify</a></div>
            </div>
            <?= CHtml::beginForm($url, 'get', array('id' => 'formCurrency', "data-ajax" => "false")); ?>
            <div class="box">
                <?= CHtml::dropDownList('currency', 'currency', $cur, array('options' => $selected)); ?>
            </div>
            <?= CHtml::endForm(); ?>
        </article>
        <?php
        foreach ($params as $k => $r) {
            if (isset($r['promos'])) {
                ?>
                <article class="room">
                    <div class="room-description">
                        <div class="photo">
                            <img src="http://www.silverlandhotels.com/data/cover/<?php echo $r['cover_photo'] ?>">
                        </div>
                        <div class="des">
                            <h3><?php echo $r['roomName']; ?></h3>
                            <p><?php echo $r['description']; ?></p>
                        </div>
                    </div>
                    <!--end room description-->
                    <div class="promotion">
                        <h3 class="title">Offer Rates</h3>
                        <table class="promo">
                            <?php
                            $i = 0;
                            $config_condition = new EMongoCriteria;
                            $config_condition->hotel = Yii::app()->session['_hotel'];
                            $config_condition->roomType = 'all';
                            $config = Config::model()->find($config_condition);

                            foreach ($r['promos'] as $key => $pr) {
                                if ($i % 2 == 0) {
                                    $class = 'odd';
                                } else {
                                    $class = 'even';
                                }
                                if ($pr['nightFrom'] <= $night):
                                    ?>
                                    <tr class="<?php echo $class; ?>">
                                        <td class="room-promotion">
                                            <p class="promotion-name"><?php echo $pr['promotion_name'] ?></p>
                                            <p class="text"><?= $pr['cancel1'] ?>
                                                <?php
                                                if (isset($pr['cancel2']))
                                                    echo '<br>' . $pr['cancel2'];
                                                if (isset($pr['cancel3']))
                                                    echo '<br>' . $pr['cancel3'];
                                                ?>
                                            </p>
                                        </td>    
                                        <td class="room-price">
                                            <p class="price"><?php
                            echo Yii::app()->session['_change_currency'] . ' ';

                            $price = 0;
                            if ($adult) {
                                switch ($adult) {
                                    case 1: $price = $pr['singleNet'];
                                        break;
                                    case 2: $price = $pr['doubleNet'];
                                        break;
                                    case 3: $price = $pr['trippleNet'];
                                        break;
                                    default: $price = $pr['singleNet'];
                                        break;
                                }
                            }
                            if ($child && $extrabed && $config['allowExtraBed']) {
                                $price += ($extrabed * $config['extraBed_adults']) * Yii::app()->session['_exchangeRate'];
                                //echo Yii::app()->session['_hotel'];
                            }
                            echo number_format($price, 2, '.', ',');
                                                ?></p>
                                            <p class="text">(Avg Daily Rate)</p>
                                        </td>
                                        <td class="button">
                                            <form action="<?= $url ?>" method="post" name="booking" onSubmit="return true" data-ajax="false">
                                                <input type="hidden" name="fromDate" value="<?= $fromDate ?>">
                                                <input type="hidden" name="toDate" value="<?= $toDate ?>">
                                                <input type="hidden" name="child" value="<?= $child ?>">
                                                <input type="hidden" name="adult" value="<?= $adult ?>">
                                                <input type="hidden" name="extrabed" value="<?= $extrabed ?>">
                                                <input type="hidden" name="roomtype" value="<?= $k; ?>">
                                                <input type="hidden" name="promotion" value="<?= $pr['PromotionId']; ?>">
                                                <input type="submit" value="BOOK" data-role="none" class="submit">
                                            </form>
                                        </td>

                                    </tr>
                                    <?php
                                endif;
                                $i++;
                            }
                            ?>
                        </table>
                    </div>
                    <!--end promotion-->
                    <div data-role="collapsibleset" data-theme="a" class="room_details">
                        <div data-role="collapsible" class="room-amenities">
                            <h3 class="title">Details</h3>
                            Room Amenities:
                            <ul class="amenities">
                                <?php
                                foreach ($r['roomFacilities'] as $k => $ameni) {
                                    echo '<li>' . ucwords(Yii::t('lang', $k)) . '</li>';
                                }
                                ?>
                            </ul>
                            <div class="slide-room">
                                <a class="arrow-left" href="#"></a> 
                                <a class="arrow-right" href="#"></a>
                                <div class="room-slide" id="room-slide<?= $ii ?>">
                                    <div class="swiper-wrapper">
                                        <?php
                                        if (isset($r['photos'])) {
                                            foreach ($r['photos'] as $pt) {
                                                echo '<div class="swiper-slide"><img src="http://www.silverlandhotels.com/data/uploads/' . $pt['photo_name'] . '"></div>';
                                            }
                                            $ii++;
                                        }
                                        ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- end room details-->
                </article>
                <?php
            }
        }
        ?>
    </section>


    <?php
} else {
    echo 'Full!';
}
?>
<script type="text/javascript">
    var countRoom = <?= $ii; ?>;
</script>
